package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class DvdCollection here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DvdCollection
{
    private static DvdCollection instance = new DvdCollection();
    ArrayList<Dvd> dvdList;

    /**
     * Constructor for objects of class DvdCollection
     */
    private DvdCollection()
    {
        dvdList = new ArrayList<Dvd>();
    }
    
    public static DvdCollection getInstance()
    {
        return instance;
    }
    
    /**
     * adds a Dvd
     */
    public void addDvd(Dvd dvd)
    {
        dvdList.add(dvd);
    }
    
    /**
     * removes a dvd
     */   
    public void deleteDvd(int ID)
    {
        Dvd dvd = null;
        int index = 0;
        boolean found = false;
        while(index < dvdList.size() && !found)
        {
            dvd = dvdList.get(index);
            if(dvd.getId() == ID)
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        if (found)
        {
            dvdList.remove(index);
        }
    }
    
    /**
     * finds a dvd object
     */
    public Dvd findDvd(int ID)
    {
        Dvd dvd = null;
        int index = 0;
        boolean found = false;
        while(index < dvdList.size() && !found)
        {
            dvd = dvdList.get(index);
            if(dvd.getId() == ID)
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        if (found)
        {
            return dvdList.get(index);
        }
        else
        {
            return null;
        }
    }

    public ArrayList<Dvd> getAllDvds() 
    {
        return dvdList;
    }


}
